
/**
 * 计算AVR震荡次数
 * @author Administrator
 * 头:  9ms 1 + 4.5ms 0
 * 地址码1: 0.56ms 0 + 0.565ms 1
 * 地址码2: 同地址码1
 * 数据码: 0.56ms 0 + 1.685ms 1
 * 数据反码.....
 */
public class CalcTimes {
	public static void main(String[] args) {
//		JingZhen jz = new JingZhen(16000000, 8);
		JingZhen jz = new JingZhen(11059200, 8);
		System.out.println("HH:	" + jz.getTimes(9));
		System.out.println("HL:	" + jz.getTimes(4.5));
		System.out.println("1H:	" + jz.getTimes(0.56));
		System.out.println("1L:	" + jz.getTimes(2.25 - 0.565));
		System.out.println("0H:	" + jz.getTimes(0.56));
		System.out.println("0L:	" + jz.getTimes(1.12 - 0.56));
	}	

	/**
	 * @param Hz
	 * @param ms
	 * @return	震荡次数
	 */
	public static double getTimes(long Hz, double ms) {
		return ms * Hz / 1000;
	}
	
	private static class JingZhen {
		
		public final long rate;
		
		/**
		 * 分频
		 */
		private int fenPin = 1;
		
		/**
		 * 新建一个JingZhen, 频率为rate, 单位Hz
		 * @param rate
		 */
		public JingZhen(long rate, int fenpin) {
			this.rate = rate;
			this.fenPin = fenpin;
		}
		
		/**
		 * 获得指定毫秒内的振动次数.
		 * @param ms	指定毫秒数
		 * @return
		 */
		public double getTimes(double ms) {
			return ms * this.rate / 1000 / fenPin;
		}
	}
}

